
#@homejs() 
#@checkToken2()
<script src="/assets/js/dateclick/WdatePicker.js"></script>
<link href="/assets/js/dateclick/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<div style="width:880px;min-height:600px;"> 
	<div align="left" style="width:860px;padding:20px 0 0 20px;;height:30px;background:#FFF">
		<span seleinfo1="normal" class="invest invest_time1 invest_time">未使用</span> 
		<span seleinfo1="used" class="invest invest_time1 ">已使用</span> 
		<span seleinfo1="expire" class="invest invest_time1">已过期</span> 
		<select id="coupontype" style="float:right;width:100px;margin-right:40px;height:30px;border:1px solid #e0e0e0;border-radius:5px;padding:2px 5px;">
		  <option value="">全部</option>
		  <option value ="jxq">加息券</option>
		  <option value ="tyj">体验金</option>
		  <option value="tzhb">返现券</option> 
		</select>
		<img style="float:right;margin-top:5px;margin-right:5px;" src="#(path)/assets/home/account/account_img16.png">
	</div>
	 
	<!--标的列表-->
	<div align="left" style="padding:10px 20px 20px 20px;;width:840px;height:600px;background:#FFF;">
		<div style="line-height:50px;font-size:14px;height:550px;">
			<div align="left" style=" border-bottom:1px dashed #e0e0e0;height:50px;background:#fafafa">
				<div style="float:left;width:130px;margin-left:20px;">名称</div>
				<div style="float:left;width:170px;">发放日期</div>
				<div style="float:left;width:180px;">适用标的</div>
				<div style="float:left;width:150px;">使用条件</div> 
				<div style="float:left;width:150px;">过期时间</div>
			</div>
			<div id="rewardlist">
				
			</div>
		</div>
		<!--分页-->
		<div align="center" style="font-size:14px;height:50px;width:100%;padding-bottom:10px;background:#FFF;line-height:50px;">
			<span id="firstpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:5px 0 0 5px;">
				首页
			</span>
			<span id="backpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				上一页
			</span>
			<span style="padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				第<span id="pageNumber"></span>页&nbsp&nbsp共<span id="totalPage"></span>页
			</span>
			<span id="nextpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;">
				下一页
			</span>
			<span id="lastpage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:0 5px 5px 0;">
				尾页
			</span>
			<span style="margin-left:50px;">第</span>
			<input id="pagenum" style="border:1px solid #ebebeb;border-radius:5px;height:32px;width:40px;padding:0 10px 0 10px;font-size:16px;"  /> 
			<span>页</span>
			<span id="gopage" style="cursor:pointer;padding:5px 10px 5px 10px;border:1px solid #ebebeb;border-radius:5px;">
				跳转
			</span>
		</div>
	</div>
</div>
<script id="demo" type="text/x-jquery-tmpl">
	<div align="left" style="border-bottom:1px dashed #e0e0e0;height:50px;">
		<div class="onellipsis" style="float:left;margin-left:20px;width:130px;color:#fa4357">${name}</div>
		<div class="onellipsis" style="float:left;width:150px;padding:0 20px 0 0;">${create_time}</div>
		<div class="onellipsis" style="float:left;width:180px;">${allow_bid}</div>
		<div class="onellipsis" style="float:left;width:150px;">${limit_amount}</div>
		<div class="onellipsis" style="float:left;width:150px;">${valid_end_time}</div>  
	</div>
</script>
<script>
	var day_limit ="";
	var createTimeStart="";      
	var createTimeStart="";      
	var createTimeEnd="";
	var types = "normal";
	var pageNumber = "";
	var page = 1;
	var totalPage = "";
	var coupontype ="";
	//时间筛选--
	mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	$(".invest_time1").click(function(){
		$(".invest_time1").removeClass("invest_time"); 
		$(this).addClass("invest_time");
		types = $(this).attr("seleinfo1");
		$("#rewardlist").empty();
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	});
	$(".yuefen").click(function(){
		createTimeStart=$("#startime").val();
		createTimeEnd=$("#endtime").val();
		$("#rewardlist").empty();
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	});
	$("#coupontype").change(function(){
		var coupontype = $("#coupontype").val();
		$("#rewardlist").empty();
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	});
	//持有与已完成转换
	$(".userinvest2").click(function(){
		$(".userinvest2").removeClass("userinvest"); 
		$(".userinvest2").css("background","#f4f5fa");
		$(this).addClass("userinvest");
		$(this).css("background","#FFF");
		types = $(this).attr("seleinfo1");
		$("#rewardlist").empty(); 
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
		
	});
	//上一页
	$("#backpage").click(function(){
		page = page-1;
		if(page <= 0){
			layer.msg("当前已是首页！",{icon:2,time:1000}); 
		}else{
			$("#rewardlist").empty();
			mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
		}
	}); 
	//下一页
	$("#nextpage").click(function(){
		page = page + 1;
		if(page > totalPage){
			layer.msg("当前已是尾页！",{icon:2,time:1000}); 
		}else{
			$("#rewardlist").empty();
			mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
		}
	}); 
	//首页
	$("#firstpage").click(function(){
		page = 1;
		$("#rewardlist").empty();
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	}); 
	//尾页
	$("#lastpage").click(function(){
		page = totalPage;
		$("#rewardlist").empty();
		mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
	});  
	//跳转
	$("#gopage").click(function(){
		page = Number($("#pagenum").val());
		if(page > totalPage || page < 1 ){
			layer.msg("输入页数不在区间内！",{icon:2,time:1000}); 
		}else{ 
			$("#rewardlist").empty();
			mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd);
		}
	});
	function mytradelist(coupontype,types,page,day_limit,createTimeStart,createTimeEnd){
		$.getJSON("#(path)/couponLog/myList?token=#(session.token??)&type="+coupontype+"&status="+types+"&size=9&page="+page+"&dayLimit="+day_limit+"&createTimeStart="+createTimeStart+"&createTimeEnd="+createTimeEnd, function(datalist) {
			console.log(datalist);
			totalPage = datalist.data.page.totalPage;
			pageNumber = datalist.data.page.pageNumber;
			if(totalPage==0){
				totalPage = 1;
			}
			if(pageNumber==0){
				pageNumber = 1;
			}
			$("#totalPage").html(totalPage);
			$("#pageNumber").html(pageNumber); 
			$.each(datalist.data.page.list, function(i, item){ 
				console.log(item);
				if(item.type=="jxq"){
					var name = item.amount+"%加息券"
				}else if(item.type=="tzhb"){
					var name = item.amount+"元返现券"
				}else if(item.type=="tyj"){
					var name = item.amount+"元体验金"
				}
				var invests = {limit_amount:item.limit_amount,allow_bid:item.allow_bid,name:name,create_time:item.create_time,valid_end_time:item.valid_end_time};
				$("#demo").tmpl(invests).appendTo('#rewardlist');
			});
		});
	}
</script>
